package com.ybxx.asset.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;

import com.ybxx.asset.model.Company;
import com.ybxx.asset.service.CompanyService;
import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.util.UUIDGenerator;
import com.ybxx.core.web.action.BaseAction;



public class CompanyAction extends BaseAction {
	@Resource
	private CompanyService companyService;
	private List<Company> companys;
	private Company company;
	private String msg="succ";
	/*删除*/
	public String remove(){
		try{
			companyService.remove(company.getCid());
		}catch(Exception ex){
			msg="企业删除失败";
		}finally{
			return "succ";
		}
	}
	/*加载查看时候需要展示的数据*/
	public String view(){
		if(company!=null && StringUtils.isNotEmpty(company.getCid())){
			company=companyService.get(company.getCid());
		}
		return "view";
	}
	public String queryPage(){
		QueryFilter filter=new QueryFilter(getRequest());
		companys=companyService.queryPage(company,filter);
		super.setRownum(filter.getPagingBean().getTotalItems());
		super.setCurrentpage(Integer.parseInt(filter.getPagingBean().getStart()+"")/Integer.parseInt(filter.getPagingBean().getPageSize()+"")+1);
		super.setPageSize(Integer.parseInt(filter.getPagingBean().getPageSize()+""));
		return "queryPage";
	}
	/*保存新增，修改信息*/
	public String save(){
		if(StringUtils.isEmpty(company.getCid())){
			company.setCid(UUIDGenerator.getUUID());
		}
		try{
			companyService.save(company);
		}catch(Exception ex){
			msg="企业信息保存失败.";
		}finally{
			return "succ";
		}
	}
	/*加载修改时候需要展示的数据*/
	public String load(){
		if(company!=null && StringUtils.isNotEmpty(company.getCid())){
			company=companyService.get(company.getCid());
		}
		return "load";
	}
	public List<Company> getCompanys() {
		return companys;
	}
	public void setCompanys(List<Company> companys) {
		this.companys = companys;
	}
	public Company getCompany() {
		return company;
	}
	public void setCompany(Company company) {
		this.company = company;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
}
